;(function (){
	    var COOK_LOGIN_NAME="USER_LOGIN_NAME";
		var ERROR = {
			USER_NAME : {
				NULL  : '用户名不能为空',
				ERROR : '用户名格式错误'
			},
			PASSWORD  : {
				NULL  : '用户登录密码不能为空',
				ERROR : '密码格式错误'
			},
			VERIFY_CODE : {
				NULL : '验证码不能为空',
				ERROR : '验证码格式错误'
			}
		}
		if($.cookie(COOK_LOGIN_NAME)){
			$('#loginForm [name="username"]').val($.cookie(COOK_LOGIN_NAME));
		}else{
			$('#loginForm [name="username"]').val('');
		}

		var login_check = function (){
			//$('#errorMessage').html('');
			var user_name = $('#loginForm [name="username"]');
			var password = $('#loginForm [name="password"]');
			var verifyCode = $('#loginForm [name="jcaptchaCode"]');
			if($.trim(user_name.val()) === '' || 
				user_name.val() === user_name.attr('data-placeholder')){
				user_name.focus();
				return {
					ele : user_name,
					error : ERROR.USER_NAME.NULL
				};
			}else if(!$.check.isUserN(user_name.val())){
				user_name.focus();
				return {
					ele : user_name,
					error : ERROR.USER_NAME.ERROR
				};
			}

			if($.trim(password.val())=='' 
				||(password.val()=== password.attr('data-placeholder'))
				 ){
				password.focus();
				return {
					ele : password,
					error : ERROR.PASSWORD.ERROR
				};
			}
			if (!$.check.isPwd(password.val())){
				password.focus();
				return {
					ele : password,
					error : ERROR.PASSWORD.ERROR
				};
			}
			if($.trim(verifyCode.val()) === '' || 
				verifyCode.val() === verifyCode.attr('data-placeholder')){
				verifyCode.focus();
				return {
					ele : verifyCode,
					error : ERROR.VERIFY_CODE.NULL
				};
			}else if(!/^[0-9a-zA-Z]{4,6}$/.test(verifyCode.val())){
				verifyCode.focus();
				return {
					ele : verifyCode,
					error : ERROR.VERIFY_CODE.ERROR
				};
			}

			return true;
		};

		var _submit_handler = function (){
			$('#loginForm [name]').unbind('focus').unbind('blur');
			var loginCheck = login_check();
			if(loginCheck==true){
				$.cookie(COOK_LOGIN_NAME, $('#loginForm [name="username"]').val(), { expires: 7 });
				$.placeholder.focusC();
				$('#loginForm')[0].submit();
				$.placeholder.blurC();
			}else{
				//$.validation.errRender(false, loginCheck['ele'][0] , loginCheck['error']);
				$.alert({
					status     : 'error',
					basicTitle : loginCheck['error']
				});
				//jQuery(loginCheck['ele'][0]).select();
				return;
			}
		}

		$(document).keydown(function (e){
			var e = e ? e :(window.event ? window.event : null); 
			window.setTimeout(function (){
				if(e.keyCode==13){
					_submit_handler();
				}
			},0);	
		});
		$('#login-submit').click(function (){
			window.setTimeout(function (){
				_submit_handler();
			},0);	
		});

		$(".jcaptcha-btn").click(function() {
            $(".jcaptcha-img").attr("src", window.frontPath+'jcaptcha?'+new Date().getTime());
        });

		$("#scrollsidebar").load(window.basePath+"static/onlineCustomer/index.html",function(){
			jQuery("#onlineCustomer").attr("src",window.basePath+"static/img/kf/ico-kefu1.png").click(
			 function()
			 {
				  window.open("http://tb.53kf.com/webCompany.php?arg=10093400&style=1",window.platform);
			 }
			);
			jQuery("#platform").html(window.platform);
			$("#scrollsidebar").fix({suspend:"left",minStatue:true,durationTime:600});
		});
		$.placeholder.init();
	    if(error)
	    {
	    	$.alert({
				status     : 'error',
				basicTitle : error
			});
	    }
	})();